home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************
- Copyright (c) 1990 Richard Lesh, All Rights Reserved
- **********************************************************/
-
- /**********************************************************
- Program: Cursor Test
-
- Demonstrates the use of animated cursors and exercises the
- Cursor Control module.
- **********************************************************/
-
- #include <MacHeaders>
- #include <SANE.h>
-
- /**********************************************************
- Definitions
- **********************************************************/
- #ifndef NULL
- #define NULL 0L
- #endif
-
- #define ABOUT_DLOG 128
-
- #define APPLE_MENU 128
- #define FILE_MENU 129
- #define EDIT_MENU 130
- #define CURSOR_MENU 131
- #define SPEED_MENU 132
-
- /**********************************************************
- TypeDefs and Enums
- **********************************************************/
-
- /* Animated cursor control structure 'acur' */
- typedef struct {
- short n;
- short index;
- union {
- Handle cursorHdl;
- short resID;
- }frame[1];
- }acurRec,*acurPtr,**acurHandle;
-
- /* Menu commands */
- enum {mAbout=1};
- enum {mStart=1,mStop,mQuit=4};
- enum {mUndo=1,mCut=3,mCopy,mPaste,mClear};
-
- /**********************************************************
- Private Globals
- **********************************************************/
- static short gCursorNum;
- static short gSpeedNum;
-
- /**********************************************************
- Prototypes
- **********************************************************/
- void main(void);
- void InitMgrs(void);
- void FillMenus(void);
- void EventLoop(void);
- void DoMenu(long command);
- void DoOpen(void);
- void DoClose(void);
-
- void InitCursorCtrl(acurHandle h);
- void QuitCursorCtrl(void);
- void SpinCursor(short cycles);
- void StopCursor(void);
- void SetCursorSpeed(short newSpeed);
-
- void Wait(short);
-
- /**********************************************************
- Routine: main()
-
- Entry point for the application.
- **********************************************************/
-
- void main()
- {
- short i;
-
- MaxApplZone();
- for (i=0;i<10;i++)
- MoreMasters();
- InitMgrs();
- FillMenus();
- DoOpen();
- EventLoop();
- DoClose();
- }
-
- /**********************************************************
- Routine: InitMgrs()
-
- This routine initializes all the appropriate managers.
- **********************************************************/
-
- void InitMgrs()
- {
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitCursor();
- FlushEvents(everyEvent,0);
- }
-
- /**********************************************************
- Routine: FillMenus()
-
- Reads in the menu bar and menu resources, then builds the
- dynamic menus.
- **********************************************************/
-
- void FillMenus()
- {
- short i;
- Handle menuBarHdl;
- MenuHandle menuHdl;
-
- menuBarHdl=GetNewMBar(128); /*Load the Menu Bar */
- SetMenuBar(menuBarHdl); /*Load the MENUs */
- menuHdl=GetMHandle(APPLE_MENU); /*Build the Apple menu*/
- AddResMenu(menuHdl,'DRVR');
- menuHdl=GetMHandle(CURSOR_MENU);/*Build the Cursor menu*/
- AddResMenu(menuHdl,'acur');
- DrawMenuBar();
- }
-
- /**********************************************************
- Routine: EventLoop()
-
- Main event loop processing.
- **********************************************************/
-
- Boolean gDone=FALSE;
- void EventLoop()
- {
- EventRecord theEvent;
- WindowPtr theWindow;
- short partCode;
-
- while (!gDone){
- SystemTask();
- GetNextEvent(everyEvent,&theEvent);
- switch(theEvent.what){
- case nullEvent:
- break;
- case keyDown:
- case autoKey:
- if (theEvent.modifiers & cmdKey){
- DoMenu(MenuKey((short)(theEvent.message & charCodeMask)));
- HiliteMenu(0);
- }
- break;
- case updateEvt:
- break;
- case activateEvt:
- break;
- case mouseDown:
- switch (partCode=FindWindow(theEvent.where,&theWindow)){
- case inDesk: break;
- case inMenuBar:
- DoMenu(MenuSelect(theEvent.where));break;
- case inSysWindow:
- SystemClick(&theEvent,theWindow);break;
- default:
- break;
- }
- break;
- case app4Evt:
- if (!(theEvent.message&suspendResumeMessage)) StopCursor();
- break;
- }
- }
- }
-
- /**********************************************************
- Routine: DoMenu(long command)
-
- Handles menu selections.
- **********************************************************/
-
- void DoMenu(long command)
- {
- short menu_id=HiWord(command);
- short item=LoWord(command);
- Str255 item_name;
- MenuHandle mHdl;
- DialogPtr dPtr;
-
- switch(menu_id){
- case APPLE_MENU:
- if (item==1){
- dPtr=GetNewDialog(ABOUT_DLOG, NULL, -1);
- while (ModalDialog(NULL, &item),item!=1);
- DisposDialog(dPtr);
- }else if (item>2){
- GetItem(GetMHandle(menu_id),item,item_name);
- OpenDeskAcc(item_name);
- }
- break;
- case EDIT_MENU:
- SystemEdit(item-1);break;
- case FILE_MENU:
- switch(item){
- case mStart:
- SpinCursor(5);
- Wait(6*60);
- break;
- case mStop:
- StopCursor();
- InitCursor();
- break;
- case mQuit:
- gDone=TRUE;
- break;
- }
- break;
- case CURSOR_MENU:
- mHdl=GetMHandle(menu_id);
- GetItem(mHdl,item,item_name);
- StopCursor();
- InitCursorCtrl((acurHandle)GetNamedResource('acur',
- item_name));
- CheckItem(mHdl, gCursorNum, FALSE);
- CheckItem(mHdl, item, TRUE);
- gCursorNum=item;
- break;
- case SPEED_MENU:
- mHdl=GetMHandle(menu_id);
- GetItem(mHdl,item,item_name);
- SetCursorSpeed((short)str2num((char *)item_name));
- CheckItem(mHdl, gSpeedNum, FALSE);
- CheckItem(mHdl, item, TRUE);
- gSpeedNum=item;
- break;
- }
- HiliteMenu(0);
- }
-
- /**********************************************************
- Routine: DoOpen()
-
- Performs tasks that need to be done at startup.
- **********************************************************/
-
- void DoOpen()
- {
- MenuHandle mHdl;
- Str255 s;
-
- gCursorNum=1; /* Select cursor #1 and update menu */
- mHdl=GetMenu(CURSOR_MENU);
- CheckItem(mHdl, gCursorNum, TRUE);
- GetItem(mHdl,gCursorNum,s);
- InitCursorCtrl((acurHandle)GetNamedResource('acur',s));
-
- gSpeedNum=5; /* Select speed #5 and update menu */
- mHdl=GetMenu(SPEED_MENU);
- CheckItem(mHdl, gSpeedNum, TRUE);
- GetItem(mHdl,gSpeedNum,s);
- SetCursorSpeed((short)str2num((char *)s));
- }
-
- /**********************************************************
- Routine: DoClose()
-
- Cleans up before shutting down the application.
- **********************************************************/
-
- void DoClose()
- {
- QuitCursorCtrl();
- }
-
- /**********************************************************
- Routine: Wait(short t)
-
- Pauses execution for t sixtieths of a second. Does not
- allow background tasks to execute.
- **********************************************************/
-
- void Wait(short t)
- {
- long s;
-
- s=TickCount()+t;
- while (TickCount()<s);
- }
-
-